<?php
/**
 * wp-foundation functions.php
 */
?>
<?php
// Path constants
define('THEMELIB', TEMPLATEPATH . '/lib');

// Load custom header extensions
require_once(THEMELIB . '/extensions/header-extensions.php');

// Load custom sidebar extensions
require_once(THEMELIB . '/extensions/sidebar-extensions.php');

// Load custom theme-options configuration
require_once(THEMELIB . '/extensions/theme-options.php');

// Load widget extensions
require_once(THEMELIB . '/extensions/widgets.php');

// Load banner extensions
require_once(THEMELIB . '/extensions/dynamic-banner.php');

// Load post extensions
require_once(THEMELIB . '/extensions/post.php');

// Load post extensions
require_once(THEMELIB . '/extensions/hooks.php');

//wp 2.9 support for thumbnails in posts
add_theme_support( 'post-thumbnails' );

// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( 'foundation', TEMPLATEPATH . '/languages' );
$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable($locale_file) )
	require_once($locale_file);


// Get the page number
function get_page_number() {
    if (get_query_var('paged')) {
        print ' | ' . __( 'Page ' , 'foundation') . get_query_var('paged');
    }
} // end get_page_number


// For category lists on category archives: Returns other categories except the current one (redundant)
function cats_meow($glue) {
	$current_cat = single_cat_title( '', false );
	$separator = "\n";
	$cats = explode( $separator, get_the_category_list($separator) );
	foreach ( $cats as $i => $str ) {
		if ( strstr( $str, ">$current_cat<" ) ) {
			unset($cats[$i]);
			break;
		}
	}
	if ( empty($cats) )
		return false;

	return trim(join( $glue, $cats ));
} // end cats_meow


// For tag lists on tag archives: Returns other tags except the current one (redundant)
function tag_ur_it($glue) {
	$current_tag = single_tag_title( '', '',  false );
	$separator = "\n";
	$tags = explode( $separator, get_the_tag_list( "", "$separator", "" ) );
	foreach ( $tags as $i => $str ) {
		if ( strstr( $str, ">$current_tag<" ) ) {
			unset($tags[$i]);
			break;
		}
	}
	if ( empty($tags) )
		return false;

	return trim(join( $glue, $tags ));
} // end tag_ur_it




// Produces an avatar image with the hCard-compliant photo class
function commenter_link() {
	$commenter = get_comment_author_link();
	if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
		$commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
	} else {
		$commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
	}
	$avatar_email = get_comment_author_email();
	$avatar = str_replace( "class='avatar", "class='photo avatar", get_avatar( $avatar_email, 80 ) );
	echo $avatar . ' <span class="fn n">' . $commenter . '</span>';
} // end commenter_link


// Custom callback to list comments in the shape style
function custom_comments($comment, $args, $depth) {
  $GLOBALS['comment'] = $comment;
	$GLOBALS['comment_depth'] = $depth;
  ?>
  	<li id="comment-<?php comment_ID() ?>" <?php comment_class() ?>>
  		<div class="comment-author vcard"><?php commenter_link() ?></div>
  		<div class="comment-meta"><?php printf(__('Posted %1$s at %2$s <span class="meta-sep">|</span> <a href="%3$s" title="Permalink to this comment">Permalink</a>', 'foundation'),
  					get_comment_date(),
  					get_comment_time(),
  					'#comment-' . get_comment_ID() );
  					edit_comment_link(__('Edit', 'foundation'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
  <?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'foundation') ?>
          <div class="comment-content">
      		<?php comment_text() ?>
  		</div>
		<?php // echo the comment reply link with help from Justin Tadlock http://justintadlock.com/ and Will Norris http://willnorris.com/
			if($args['type'] == 'all' || get_comment_type() == 'comment') :
				comment_reply_link(array_merge($args, array(
					'reply_text' => __('Reply','foundation'), 
					'login_text' => __('Log in to reply.','foundation'),
					'depth' => $depth,
					'before' => '<div class="comment-reply-wrap">', 
					'after' => '</div>'
				)));
			endif;
		?>
<?php } // end custom_comments


// Custom callback to list pings
function custom_pings($comment, $args, $depth) {
       $GLOBALS['comment'] = $comment;
        ?>
    		<li id="comment-<?php comment_ID() ?>" class="<?php comment_class() ?>">
    			<div class="comment-author"><?php printf(__('By %1$s on %2$s at %3$s', 'foundation'),
    					get_comment_author_link(),
    					get_comment_date(),
    					get_comment_time() );
    					edit_comment_link(__('Edit', 'foundation'), ' <span class="meta-sep">|</span> <span class="edit-link">', '</span>'); ?></div>
    <?php if ($comment->comment_approved == '0') _e('\t\t\t\t\t<span class="unapproved">Your trackback is awaiting moderation.</span>\n', 'foundation') ?>
            <div class="comment-content">
    			<?php comment_text() ?>
			</div>
<?php } // end custom_pings ?>
<?php 
// Footer scripts
function jquery_init() {
	if (!is_admin()) {
		wp_deregister_script('jquery');
		wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', false, '1.3.2', true);
		wp_enqueue_script('jquery');

		wp_enqueue_script('supersubs_script', get_bloginfo('template_url') . '/lib/js/plugins.js', array('jquery'), '1.0', true);
		wp_enqueue_script('foundation_script', get_bloginfo('template_url') . '/lib/js/foundation.js', array('jquery'), '1.0.3', true);
	}elseif (is_admin()){
		add_thickbox();
		wp_enqueue_script('jqueryui_script', get_bloginfo('template_url') . '/lib/js/jquery-ui-1.7.2.custom.min.js', array('jquery'), '1.7.2', true);
		wp_enqueue_script('foundation_script', get_bloginfo('template_url') . '/lib/js/foundation-admin.js', array('jquery'), '1.0.3', true);
	}
}
add_action('init', 'jquery_init');
// END :Footer scripts

//add css/js to admin page
function fd_admin_css() {
    $url = get_bloginfo( 'template_directory' ) . '/lib/css/';
    echo '<link rel="stylesheet" type="text/css" href="' . $url . 'wp-fd-admin.css" />';
    add_thickbox();
}
add_action('admin_head', 'fd_admin_css');
//END: admin css/js


function fd_layout_css(){
	global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if($fd_column_structure == "2 Column Fixed With Nav Right"){$layoutUrl = 'fixed2cr.css"';}
	elseif($fd_column_structure == "2 Column Fixed With Nav Left"){$layoutUrl = 'fixed2cl.css"';}
	elseif($fd_column_structure == "2 Column Fluid With Nav Left"){$layoutUrl = 'fluid2cl.css"';}
	
	$url = get_bloginfo( 'template_directory' ) . '/lib/css/' . $layoutUrl;
    echo '<link rel="stylesheet" type="text/css" href="' . $url . ' />';
}
add_action('wp_head', 'fd_layout_css');


function foundation_top_nav_set($options){ 
foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
?><div id="dynamic-top-nav-wrap" class="wrapper">
		<div class="skip-link">
			<a href="#content" title="<?php _e( 'Skip to content', 'foundation' ) ?>"><?php _e( 'Skip to content', 'foundation' ) ?></a>
		</div>
	<nav>
	    <ul id="dynamic-top-nav" class="nav main">
	    <?php if (is_home() || is_front_page()){$current = " current_page_item";}else{$current = "";} ?>
	    <?php if (get_option('fd_home_link') == 'Disable') { ?>
	    <?php { echo ''; } ?>
	    <?php } else { echo '<li class="page_item page-item-home' . $current . '"><a href="' . get_bloginfo('url') . '">Home</a></li>'; } ?>
	    <?php wp_list_pages("depth=3&include=$fd_include_page&exclude=$fd_exclude_page&title_li="); ?>
	    </ul>
	    <?php foundation_inside_dynamic_top_nav(); ?>
    </nav>
    </div><!-- .eof dynamic-top-nav-wrap -->
<?php } 
add_action('foundation_top_nav', 'foundation_top_nav_set');
?>